package com.longrise.android.byjk.plugins.hra.hratabsecond;


import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.longrise.android.byjk.R;
import com.longrise.android.byjk.plugins.hra.HraSearchActivity;
import com.longrise.common.base.BaseFragment;
import com.longrise.common.utils.AppUtil;

/**
 * Created by Administrator on 2018/1/3.
 *  HRA--我的预约
 */

public class MineAppointFragment extends BaseFragment{

    private static final String TAG = "MineAppointFragment";
    public static final int MINEAPPOINT = 2;
    private TabLayout mTb;
    private ViewPager mVp;
    private Toolbar mToolbar;
    private RelativeLayout mRlToolbarrightiv;
    private ImageView mIvToolbarRightiv;

    @Override
    protected int getLayoutResourse(@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_mine_appoint;
    }

    @Override
    public void initView() {
        mToolbar = (Toolbar) mRootView.findViewById(R.id.byjk_toolbar);
        mTb = (TabLayout) mRootView.findViewById(R.id.mine_appoint_tablayout);
        mVp = (ViewPager) mRootView.findViewById(R.id.mine_appoint_viewpager);
        mRlToolbarrightiv = (RelativeLayout) mRootView.findViewById(R.id.bb_toolbar_right_rl);
        mIvToolbarRightiv = (ImageView) mRootView.findViewById(R.id.iv_toolbar_share);
        mToolbar.setTitle(AppUtil.getString(R.string.mine_appoint));
        setToolbarRightIvTitle(R.drawable.by_ic_search_main);
        initAdapter();
        initEvent();
    }


    public void initAdapter(){
        MineAppointPagerAdapter pagerAdapter = new MineAppointPagerAdapter(mActivity.getSupportFragmentManager());
        mVp.setAdapter(pagerAdapter);
        mTb.setupWithViewPager(mVp);
    }

    public void initEvent(){
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getActivity().finish();
            }
        });
    }

    /**
     * 显示toolbar右边面的iv
     */
    public void setToolbarRightIvTitle(int id) {
        mRlToolbarrightiv.setVisibility(View.VISIBLE);
        mIvToolbarRightiv.setVisibility(View.VISIBLE);
        mIvToolbarRightiv.setImageResource(id);
        mRlToolbarrightiv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //点击toolbar右边的iv,开启搜索界面
                Intent intent = new Intent(mContext,HraSearchActivity.class);
                intent.setFlags(MINEAPPOINT);
                startActivity(intent);
            }
        });
    }

}
